<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function maxSubArray(arr) {
            let dp = arr[1]
            let sum = arr[1]
        
        for (let i = 2; i < arr.length; i++) {
            dp = Math.max(dp + arr[i] ,arr[i])
            // 数组中最大值
            sum = Math.max(sum,dp) 
        }
        return sum
      }
      console.log(maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4]))
    
    </script>
</body>
</html>